package cn.jsony.org.service.impl;

import cn.jsony.basic.util.PageList;
import cn.jsony.org.domain.Employee;
import cn.jsony.org.mapper.EmployeeMapper;
import cn.jsony.org.query.EmployeeQuery;
import cn.jsony.org.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public List<Employee> findAll() {
        return employeeMapper.loadAll();
    }

    @Override
    public Employee findOne(Long id) {
        return employeeMapper.loadById(id);
    }

    @Override
    @Transactional
    public void add(Employee employee) {
        employeeMapper.save(employee);
    }

    @Override
    @Transactional
    public void del(Long id) {
        employeeMapper.remove(id);
    }

    @Override
    @Transactional
    public void update(Employee employee) {
        employeeMapper.update(employee);
    }

    @Override
    public PageList<Employee> queryPage(EmployeeQuery query) {
        //先查询总数量
        Integer count = employeeMapper.queryCount(query);
        if(count == null || count == 0){//没有数据
            return  new PageList<>();
        }
        //再查询当前页的分页数据
        List<Employee> employees = employeeMapper.queryData(query);

        return new PageList<>(count,employees);
    }

    @Override
    public void patchDel(List<Long> ids) {

    }
}
